package com.erro;

import java.lang.reflect.Field;

/**
 * @author zhuangqi
 * @date 2017/6/2.
 */
public class IntegerSwap {

    public static void main(String[] args) {
        Integer a=1, b=2;
        System.out.println("before : a = " +a+ ", b ="+b);
        swap(a,b);
        System.out.println("after : a = " +a+ ", b ="+b);
    }
    public static void swap(Integer i1,Integer i2){
        try {
            Field f = Integer.class.getDeclaredField("value");
            f.setAccessible(true);
            int tmp = i1.intValue();
            f.set(i1,i2.intValue());
            f.set(i2,tmp);
        } catch (NoSuchFieldException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
    }

}
